package Java9_2.Test_3;

public class Teacher{
    private String name;
    private int age;
    private String school;

    public Teacher(String name, int age, String school) throws Exception{
        this.name = name;
        setAge(age);
        this.school = school;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age)throws Exception {
        if (age>=22){
            this.age=age;
        }else{
            Exception e=new Exception("年龄小于22岁");
            throw e;
        }
    }

    public String getSchool() {
        return school;
    }

    public void setSchool(String school) {
        this.school = school;
    }

    public void teach(){
        System.out.println(getName()+"在上课");
    }
    public void introduce(){
        System.out.println(getName()+"在自我介绍");
    }
}
